package com.wn.controller;

import com.common.entity.PageParam;
import com.common.entity.Rout;
import com.common.entity.Rsp;
import com.github.pagehelper.PageInfo;
import com.wn.service.RoutService;
import com.wn.service.RoutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class RoutController {

    @Autowired
    RoutService routService;

    /**
     * @ClassName
     * @Description : 分页查询路线
     * @param: pageParam
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @PostMapping("searchSomeByPageRout")
    public Rsp searchSomeByPageRout(@RequestBody PageParam<Rout> pageParam,
                                    @RequestHeader("token") String token){
        PageInfo<Rout> pg = routService.searchSomeByPage(pageParam);
        return Rsp.success(pg);
    }

    /**
     * @ClassName
     * @Description :根据id查询路线信息
     * @param : id
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @GetMapping("getOneByIdRout/{id}")
    public Rsp getOneByIdRout(@PathVariable("id") String id,
                              @RequestHeader("token") String token){
        Rout oneById = routService.getOneById(id);
        return Rsp.success(oneById);
    }


    /**
     * @ClassName
     * @Description : addOne添加路线
     * @param:
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @PostMapping("addOneRout")
    public Rsp addOneRout(@RequestBody Rout Rout,
                          @RequestHeader("token") String token){
        return routService.addOne(Rout);
    }

    /**
     * @ClassName
     * @Description : update修改路线
     * @param :
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @PostMapping("updateRout")
    public Rsp updateRout(@RequestBody Rout Rout,
                          @RequestHeader("token") String token){
        return routService.update( Rout);
    }


    /**
     * @ClassName
     * @Description : deleteLogical逻辑删除路线
     * @param :
     * @Return :
     * @Author : 汪雄
     * @Date :
     */
    @PostMapping("deleteLogicalRout")
    public Rsp deleteLogicalRout(@RequestBody Rout rout,
                                 @RequestHeader("token") String token){
        return routService.deleteLogical(rout);
    }


    @PostMapping("getRoutByName")
    public Rsp getRoutByName(@RequestBody String name,
                              @RequestHeader("token") String token){

        return  routService.getRoutByName(name);
    }
}
